/**
 * 2012-2-26
 * @author 李亚松
 * @email  lysong01@gmail.com
 * RandomGenerator.java
 */
package liyasong.util;

import java.util.Random;

public class RandomGenerator {
	private static Random r = new Random(47);
	public static class 
	Boolean implements Generator<java.lang.Boolean> {
		@Override
		public java.lang.Boolean next() {
			return r.nextBoolean();
		}
	}
	
	public static class 
	Byte implements Generator<java.lang.Byte> {
		@Override
		public java.lang.Byte next() {
			return (byte)r.nextInt();
		}
	}

	public static class 
	Character implements Generator<java.lang.Character> {
		@Override
		public java.lang.Character next() {
			return CountingGenerator.chars[
			    r.nextInt(CountingGenerator.chars.length)];
		}
	}
	
	public static class 
	String extends CountingGenerator.String {
		{cg = new Character();}		//Plug in the random Character generator; 加{}是什么意思呢？
		public String() {}
		public String(int length) { super(length);}
	}
	
	public static class 
	Short implements Generator<java.lang.Short> {
		public java.lang.Short next() { return (short)r.nextInt(); }
	}
	
	public static class 
	Integer implements Generator<java.lang.Integer> {
		private int mod = 10000;
		public Integer() {}
		public Integer(int modulo) { mod = modulo; }
		public java.lang.Integer next() { return r.nextInt(mod); }
	}
	
	public static class 
	Double implements Generator<java.lang.Double> {
		public java.lang.Double next() { 
			long trimmed = Math.round(r.nextDouble() * 100);	//这是为什么呢？
			return ((double)trimmed) / 100; 
		}
	}
}
